#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> PII;

int dx[4] = { 1, -1 , 0 , 0 };
int dy[4] = { 0 , 0 ,  1 , -1 };

bool visited[110][110] = { false };
int m, n;
queue<PII> q;

int nearestExit(vector<vector<char>>& maze, vector<int>& e) {
    m = maze.size(), n = maze[0].size();
    q.push({ e[0] , e[1] });
    int ret = 0;
    visited[e[0]][e[1]] = true;

    while (!q.empty())
    {
        int size = q.size();

        for (int i = 0; i < size; ++i)
        {
            auto [a, b] = q.front();
            q.pop();

            for (int i = 0; i < 4; ++i)
            {
                int x = a + dx[i], y = b + dy[i];
                if (x >= 0 && x < m && y >= 0 && y < n && maze[x][y] == '.' && !visited[x][y])
                {

                    if (x == 0 || y == 0 || x == m - 1 || y == n - 1)
                        return ret + 1;
                    visited[x][y] = true;
                    q.push({ x,y });
                }
            }
        }

        ++ret;
    }

    return -1;
}

int main()
{

	return 0;
}